﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    ingredientDAO dao;
    Ingredient ingredient;
    protected void Page_Load(object sender, EventArgs e)
    {
        dao = new ingredientDAO();
        ingredient = new Ingredient();
        load_data();

    }
    public void load_data()
    {
        DataSet ds = new DataSet();
        ds = (DataSet)Session["USER"];
        String UserID = ds.Tables[0].Rows[0]["UserID"].ToString();
        ds = dao.getByUser(UserID);
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("addIngredient.aspx");
    }
    
    protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
        String id = GridView1.DataKeys[e.NewSelectedIndex].Value.ToString();
        ingredient.IngredientID1 = id;
        DataSet ingredientUpdate = new DataSet();
        ingredientUpdate = dao.getIngredient(ingredient);
        Session.Add("INGRE", ingredientUpdate);
        Response.Redirect("detailIngredient.aspx");
    }
}